/**
 * File Comment: Ita a GUI
 */
package edu.gatech.oad.project.presentation;
//$codepro.audit.disable
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;

import edu.gatech.oad.project.operations.data.Appointment;

/**
 * This class is a panel that allows the user
 * to interact with the GUI to view appointments
 * by date.
 * 
 * @author Group 17
 * @version 1
 */
public class NurseAppByDate extends JPanel {
  
  /**
   * Field driver: holds the Driver connected to the GUI
   */
  private Driver driver;
  
  /**
   * Field lblAppointmentsForToday: label
   */
  public JLabel lblAppointmentsForToday;
  
  /**
   * Field list: list of appointments for a given date
   */
  public JList list;
  
  /**
   * Field btnViewedit: view/edit button
   */
  public JButton btnViewedit;
  
  /**
   * Field btnBackToHome: back button
   */
  public JButton btnBackToHome;
  
  /**
   * Field selected: the Appointment to edit
   */
  private Appointment selected;

 /**
  * Constructor.
  * 
  * @param driver the Driver connected to the GUI
  */
 public NurseAppByDate(Driver driver) {
   this.driver = driver;
  GridBagLayout gridBagLayout = new GridBagLayout();
  gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0};
  gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0};
  gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
  gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
  setLayout(gridBagLayout);
  
  lblAppointmentsForToday = new JLabel("Appointments for Today");
  lblAppointmentsForToday.setFont(new Font("Lucida Grande", Font.PLAIN, 30));
  GridBagConstraints gbc_lblAppointmentsForToday = new GridBagConstraints();
  gbc_lblAppointmentsForToday.insets = new Insets(0, 0, 5, 0);
  gbc_lblAppointmentsForToday.gridwidth = 6;
  gbc_lblAppointmentsForToday.gridx = 0;
  gbc_lblAppointmentsForToday.gridy = 0;
  add(lblAppointmentsForToday, gbc_lblAppointmentsForToday);
  
  //write code to get list of appointments and display
  list = new JList();
  GridBagConstraints gbc_list = new GridBagConstraints();
  gbc_list.gridwidth = 2;
  gbc_list.gridheight = 2;
  gbc_list.insets = new Insets(0, 0, 5, 5);
  gbc_list.fill = GridBagConstraints.BOTH;
  gbc_list.gridx = 1;
  gbc_list.gridy = 1;
  add(list, gbc_list);
  
  btnViewedit = new JButton("View/Edit");
  btnViewedit.addActionListener(new ButtonListener1(this));
  GridBagConstraints gbc_btnViewedit = new GridBagConstraints();
  gbc_btnViewedit.insets = new Insets(0, 0, 0, 5);
  gbc_btnViewedit.gridx = 1;
  gbc_btnViewedit.gridy = 3;
  add(btnViewedit, gbc_btnViewedit);
  
  btnBackToHome = new JButton("Back to Home");
  btnBackToHome.addActionListener(new ButtonListener2(this));
  GridBagConstraints gbc_btnBackToHome = new GridBagConstraints();
  gbc_btnBackToHome.insets = new Insets(0, 0, 0, 5);
  gbc_btnBackToHome.gridx = 2;
  gbc_btnBackToHome.gridy = 3;
  add(btnBackToHome, gbc_btnBackToHome);
 } // end constructor method
 
 /**
  * Get the Driver.
  * 
  * @return the Driver connected to the GUI
  */
 public Driver getDriver()
 {
   return this.driver;
 } // end getDriver method
 
 /**
  * Get the selected Appointment.
  * 
  * @return the selected Appointment.
  */
 public Appointment getSelected()
 {
   return this.selected;
 } // end getSelected method
 
 /**
  * This private inner class implements ActionListener for btnViewedit.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener1 implements ActionListener
 {
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Field apps: the NurseAppByDate being used
    */
   private NurseAppByDate apps;
   
   /**
    * Constructor.
    * 
    * @param apps the NurseAppByDate being used
    */
   private ButtonListener1(NurseAppByDate apps)
   {
     this.apps = apps;
     this.driver = apps.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     this.driver.getFrame().setContentPane(new NursePatientTR(this.driver,this.apps.getSelected()));
     this.driver.getFrame().pack();
   } // end actionPerformed method
 } // end ButtonListener1 class

 /**
  * This private inner class implements ActionListener for btnBackToHome.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener2 implements ActionListener
 {
   /**
    * Field apps: the NurseAppByDate being used
    */
   private NurseAppByDate apps;
   
   /**
    * Field driver: holds the Driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param apps the NurseAppByDate being used
    */
   private ButtonListener2(NurseAppByDate apps)
   {
     this.apps = apps;
     this.driver = apps.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     this.driver.getFrame().setContentPane(new NurseHome(this.driver));
     this.driver.getFrame().pack();
   } // end actionPerformed method
 } // end ButtonListener2 class
} // end NurseAppByDate class